// pages/user_ticket/user_ticket.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    _num1: 1,
    ticketList:[],
    ticketList1:[],
    isEmp:false, // 是否为空
    isEmp1:false, // 是否为空
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //获取优惠券列表
    // 未核销
    wx.request({
      url: app.d.hostUrl + '/api/coupon/getMyCouponList',
      method: 'post',
      data: {
        sessionkey: wx.getStorageSync('sessionkey'),
        is_used:0,
        page:1,
        sessionkey: wx.getStorageSync('sessionkey')
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res);
        var ticketList = res.data.data;
        var len = ticketList.length;
        if(len > 0){
          that.setData({
            ticketList: ticketList,
            isEmp: false,
          });
        }else{
          that.setData({
            isEmp: true,
          });
        }
        
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          icon:"none",
          duration: 2000
        });
      },
    });

     // 已核销
     wx.request({
       url: app.d.hostUrl + '/api/coupon/getMyCouponList',
      method: 'post',
      data: {
        sessionkey: wx.getStorageSync('sessionkey'),
        is_used:2,
        page:1,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res);
        var ticketList1 = res.data.data;
        var len1 = ticketList1.length;
        if(len1 > 0){
          that.setData({
            ticketList1: ticketList1,
            isEmp1: false,
          });
        }else{
          that.setData({
            isEmp1: true,
          });
        }
        
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          icon:"none",
          duration: 2000
        });
      },
    });

  },

  //切换状态
  isCancel: function (e) {
    var that = this;
    // console.log(e.currentTarget)
    that.setData({
      _num1: e.currentTarget.dataset.num
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})